home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / UUPC3 / MAC_SPEC / UNIX_LIB / SPLITNAM.C < prev   
Text File  |  1988-03-10  |  626b  |  47 lines

  1.  
  2.  
  3. /* splitname
  4.  
  5.         split and and copy directory and filename from 
  6.         pathname to dir and name
  7. */
  8. splitname( path, dir, name )
  9. char * path;
  10. char * dir;
  11. char * name;
  12. {
  13.     register char *cp;
  14.     register int i;
  15.  
  16.     strcpy( dir, path );
  17.     i = strlen( dir);
  18.     cp = dir + i;
  19.  
  20.  
  21.     while ((i-- > 0) && (*--cp != '/') && (*cp != ':') );
  22.  
  23.     if (*cp == '/') cp++;
  24.     else if (*cp == ':') cp++;
  25.     
  26.     strcpy( name, cp );
  27.     *cp = '\0';
  28.  
  29. }
  30.  
  31. #ifdef TEST
  32. #include <stdio.h>
  33.  
  34. main ()
  35.  
  36. {
  37.     char buf[100];
  38.     char dir[100], name[100];
  39.  
  40.     while (gets( buf ) != NULL ) {
  41.         splitname( buf, dir, name );
  42.         printf( "%s -> \"%s\"   \"%s\"\n", buf, dir, name );
  43.     }
  44. }
  45.  
  46. #endif
  47.